﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Liolikas.LiolikasGame;
using System.Threading.Tasks;

namespace Liolikas.GameObjects
{
    abstract class Character : GameObject
    {

        

        protected int positionUpdateInterval;
        protected int framesToPosUpdate;
        protected Thread mover;
            
        protected Character(int hCoord, int wCoord):base(hCoord, wCoord)
        {

        }

        virtual public void Reset()
        {
            this.hCoord = initHCoord;
            this.wCoord = initWCoord;
            UpdateCoordinates();
            Init();
        }


        public void Init()
        {
            mover = new Thread(Move);
            mover.Start();

        }


        protected void Move (){
            while (!Game.GetGame().isOver)
            {
                MakeStep();
                Thread.Sleep(positionUpdateInterval);
            }
        }


        internal bool IfMoveThisFrame()
        {
            if (framesToPosUpdate == 0) framesToPosUpdate = positionUpdateInterval;
            if (framesToPosUpdate == 1)
            {
                framesToPosUpdate = positionUpdateInterval;
                return true;
            }
            else
            {
                framesToPosUpdate--;
                return false;
            }
        }
    }
}
